package com.mmall.controller;

import com.mmall.common.ServerResponse;
import com.mmall.dto.AclModuleDto;
import com.mmall.param.AclModuleParam;
import com.mmall.service.ISysAclModuleService;
import com.mmall.service.ISysTreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @Author wangtengyu
 * @Create 2018-03-13-15:49
 */
@Controller
@RequestMapping("/sys/aclModule")
@Slf4j
public class SysAclModuleController {

    @Autowired
    private ISysAclModuleService iSysAclModuleService;

    @Autowired ISysTreeService iSysTreeService;
    /**
     * 界面
     * @return
     */
    @RequestMapping("/acl.page")
    public ModelAndView page(){
        return new ModelAndView("acl");
    }

    /**
     * 新增
     * @param param
     * @return
     */
    @RequestMapping("/save.json")
    @ResponseBody
    public ServerResponse saveAclModule(AclModuleParam param){
        iSysAclModuleService.save(param);
        return ServerResponse.createBySuccess("新增权限模块成功");
    }

    /**
     * 更新
     * @param param
     * @return
     */
    @RequestMapping("/update.json")
    @ResponseBody
    public ServerResponse updateAclModule(AclModuleParam param){
        iSysAclModuleService.update(param);
        return ServerResponse.createBySuccess("更新权限模块成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("/delete.json")
    @ResponseBody
    public ServerResponse delete(@RequestParam(name="id") int id){
        iSysAclModuleService.delete(id);
        return ServerResponse.createBySuccess("删除权限模块成功");
    }

    /**
     * 返回树形结构数据
     * @return
     */
    @RequestMapping("tree.json")
    @ResponseBody
    public ServerResponse tree(){
        List<AclModuleDto> dtoList=iSysTreeService.aclModuleTree();
        return ServerResponse.createBySuccess(dtoList);
    }

}
